package singleton;

/**
 * @Author: linKe
 * @Date: 2022/1/15 15:25
 * @FileName: S1
 * @version: 1.0
 * @Description: 第一种单例模式    直接同步
 */
public class S1 {
    public static void main(String[] args) {
        S1 instance = S1.getInstance();
        System.out.println(instance);
        //singleton.S1@7f31245a
        for (int i = 0; i < 3; i++) {
            System.out.println(S1.getInstance());
            /*
            singleton.S1@7f31245a
            singleton.S1@7f31245a
            singleton.S1@7f31245a
             */
        }
    }
    private static S1 s1;

    private S1() {}

    /**
     * 直接同步关键字
     * @return  结果
     */
    public synchronized static S1 getInstance() {
        if(s1 == null) {
            s1 = new S1();
        }
        return s1;
    }

}